package com.ruoyi.api.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.product.dto.FavoritesAddParam;
import com.ruoyi.product.dto.PageQuery;
import com.ruoyi.product.service.IProductFavoritesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/api/product/favorites")
@Api(tags = "商品收藏接口")
public class ApiProductFavoritesController extends ApiBaseController{

    @Autowired
    private IProductFavoritesService productFavoritesService;

    @PostMapping("/add_old")
    @ApiOperation("新增用户收藏")
    @Deprecated
    public AjaxResult addFavorites (@Valid FavoritesAddParam param) {
        Long userId = checkLogin();
        return productFavoritesService.addFavorites(userId, param);
    }

    @PostMapping("/add")
    @ApiOperation("新增用户收藏")
    public AjaxResult addFavorites (Long productId) {
        Long userId = checkLogin();
        return productFavoritesService.addFavorites(userId, productId);
    }

    @PostMapping("/del")
    @ApiOperation("删除用户收藏")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "productIds", value = "商品id列表" ,required = true, allowMultiple = true)
    )
    public AjaxResult delFavorites (@RequestBody List<String> productIds) {
        Long userId = checkLogin();
        return productFavoritesService.delFavorites(userId, productIds);
    }

    @GetMapping("/list")
    @ApiOperation("获取用户收藏列表")
    public AjaxResult queryFavorites(@Valid PageQuery pageQuery) {
        Long userId = checkLogin();
        return productFavoritesService.queryFavorites(userId,pageQuery);
    }
}
